package com.reform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reform.pojo.phase.DepartmentPhase;
import com.reform.mapper.DepartmentPhaseMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IDepartmentPhaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-10-25
 */
@Service
public class DepartmentPhaseServiceImpl extends ServiceImpl<DepartmentPhaseMapper, DepartmentPhase> implements IDepartmentPhaseService {

    @Autowired
    private DepartmentPhaseMapper departmentPhaseMapper;

    @Override
    public Result addDepartmentPhase(DepartmentPhase departmentPhase) {
        if (departmentPhaseMapper.insert(departmentPhase) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.failure(ResultCode.FAILURE);
    }

    @Override
    public Result updateDepartmentPhase(DepartmentPhase departmentPhase) {
        if (departmentPhaseMapper.updateById(departmentPhase) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.failure(ResultCode.FAILURE);
    }

    @Override
    public Result getDepartmentPhase() {
        return Result.success(ResultCode.SUCCESS, departmentPhaseMapper.selectList(null));
    }

    @Override
    public Result getDepartmentPhaseByDepId(Integer depId) {
        return Result.success(ResultCode.SUCCESS, departmentPhaseMapper.selectList(new QueryWrapper<DepartmentPhase>().eq("dep_id", depId)));
    }

    @Override
    public Result getDepartmentPhaseByPhaseId(String phaseId) {
        return Result.success(ResultCode.SUCCESS, departmentPhaseMapper.selectList(new QueryWrapper<DepartmentPhase>().eq("batch_id", phaseId)));
    }
}
